home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 654 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.2 KB

  1. Path: engnews1.Eng.Sun.COM!taumet!clamage
  2. From: lars.farm@nts.mh.se (Lars Farm)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: 'const' in header files
  5. Date: 7 Mar 1996 15:44:51 GMT
  6. Organization: pv
  7. Approved: clamage@eng.sun.com (comp.std.c++)
  8. Message-ID: <AD64B66E966816216@sleipner.nts.mh.se>
  9. References: <AD5A0C5196681CA0D@sleipner.nts.mh.se> <31379F8F.7659@compuserve.com>
  10. NNTP-Posting-Host: taumet.eng.sun.com
  11. Mime-Version: 1.0
  12. Content-Type: text/plain; charset="iso-8859-1"
  13. Content-Transfer-Encoding: 8bit
  14. X-Nntp-Posting-Host: sleipner.nts.mh.se
  15. X-Lines: 34
  16. Content-Length: 1346
  17. Originator: clamage@taumet
  18.  
  19. In article <31379F8F.7659@compuserve.com>,
  20. "John I. Moore, Jr." <70672.1744@compuserve.com> wrote:
  21.  
  22. >I think that there may be some misunderstanding about what a const data 
  23. >member actually represents.  
  24.  
  25. No. I'm not talking about member constants.
  26.  
  27. >In general, a const defined at file scope can be 
  28. >of any type.  In C++, it is generally preferable to use const instead of 
  29. >#define.
  30. >
  31. > const int maxSize = 100;   //preferable to "#define maxSize 100"
  32.  
  33. Yes and I think this is standard practice. People rely on the fact that
  34. unused constants are optimized away. Unfortunately, it appears that some
  35. compiler writers do this only for the special case of integer types. I see
  36. no reason why this should be any different:
  37.  
  38.   const float F = 1.234;     //should be preferable to "#define F 1.234"
  39.  
  40. Isuggested that required behaviour was that these constants are not
  41. instantiated unless actually used, much like templates. Rather than leaving
  42. it as an optional optimization as it appears to be now. This should apply
  43. to any built in type. Thus invalidating stupid warnings about unused
  44. variables. If some compilers warn about this, and according to the thread
  45. in c.l.c++.moderated some do, then many users will have to revert to the
  46. #define style constants instead. Is that the intent of the language
  47. designers?
  48.  
  49.  
  50. --
  51. Lars Farm, lars.farm@nts.mh.se
  52.  
  53.  
  54. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your
  55.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  56.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  57.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  58.   Comments? mailto:std-c++-request@ncar.ucar.edu
  59. ]
  60.